package com.wus.common.core.account;

import com.wus.common.core.domain.user.AccountInfo;

/**
 * @Description: 用户账号上下文信息传递
 * @Author: wus
 * @Date: 2024/12/17 11:09
 */
public class AccountThreadLocal {

    private AccountThreadLocal() {
    }

    private static final ThreadLocal<AccountInfo> LOCAL = new ThreadLocal<>();

    public static void set(AccountInfo accountInfo) {
        LOCAL.set(accountInfo);
    }

    public static AccountInfo get() {
        AccountInfo accountInfo = LOCAL.get();
        return accountInfo;
    }

    /**
     * 获取用户id
     */
    public static Long getAccountId() {
        return LOCAL.get() == null ? null : LOCAL.get().getUserId();
    }

    /**
     * 移除本地线程
     */
    public static void remove() {
        LOCAL.remove();
    }
}

